package com.bmlstrategys
{
	import com.Global;
	import com.strategy.IBML;
	import com.utils.Utils;
	
	import flash.utils.ByteArray;
	import flash.utils.Dictionary;
	
	public class TaskInfo extends BMLBase implements IBML
	{
		public function TaskInfo(data:ByteArray)
		{
			super(data);
		}
		
		public function bmlstrategyxml():XML
		{
			var num:Number = Utils.readHead(bmlData);
			var index:int=0;
			var xmlData:XML = new XML();
			xmlData = <root/>;
			
			while(index<num)
			{
				xmlData.appendChild(<tasks/>);
				xmlData.tasks[index].@taskId = bmlData.readUnsignedInt();
				xmlData.tasks[index].@title = Utils.readString(bmlData);
				xmlData.tasks[index].@objectives = Utils.readString(bmlData);
				xmlData.tasks[index].@taskDes = Utils.readString(bmlData);
				xmlData.tasks[index].@taskProcessFinish = Utils.readString(bmlData);
				xmlData.tasks[index].@taskFinish = Utils.readString(bmlData);
				xmlData.tasks[index].@taskUnFinish = Utils.readString(bmlData);
				xmlData.tasks[index].@taskType = bmlData.readUnsignedInt();
				xmlData.tasks[index].@flags = bmlData.readUnsignedInt();
				xmlData.tasks[index].@quality = bmlData.readUnsignedInt();
				xmlData.tasks[index].@taskNpcId = bmlData.readUnsignedInt();
				xmlData.tasks[index].@taskNPC = Utils.readString(bmlData);
				xmlData.tasks[index].@taskCommitNpcId = bmlData.readUnsignedInt();
				xmlData.tasks[index].@taskCommitNPC = Utils.readString(bmlData);
				xmlData.tasks[index].@taskNPCAndPoint = Utils.readString(bmlData);
				xmlData.tasks[index].@minLevel = bmlData.readUnsignedInt();
				xmlData.tasks[index].@maxLevel = bmlData.readUnsignedInt();
				xmlData.tasks[index].@requireJob = bmlData.readUnsignedInt();
				xmlData.tasks[index].@limitTime = bmlData.readUnsignedInt();
				xmlData.tasks[index].@preTaskId = bmlData.readUnsignedInt();
				xmlData.tasks[index].@nextTaskId = bmlData.readUnsignedInt();
				xmlData.tasks[index].@rewardGold = bmlData.readUnsignedInt();
				xmlData.tasks[index].@rewardExp = bmlData.readUnsignedInt();
				
				var tmpStr:String="";
				var tmp:uint;
				tmp = 0;
	
				//[[0,0],[0,0]]
				tmpStr = "[";
				while(tmp<3)
				{
					tmpStr = tmpStr+"["+bmlData.readUnsignedInt()+"-"+bmlData.readUnsignedInt()+"]";
					if(tmp<2)
					{
						tmpStr = tmpStr+",";
					}
					tmp++;
				}
				tmpStr = tmpStr+"]";
				xmlData.tasks[index].@questItemReward = tmpStr;
				
				tmp = 0;
				tmpStr = "[";
				
				while (tmp < 5)
				{
					tmpStr = tmpStr+"["+bmlData.readUnsignedInt()+"-"+bmlData.readUnsignedInt()+"]";
					if(tmp<4)
					{
						tmpStr = tmpStr+",";
					}
					tmp++;
				}
				tmpStr = tmpStr+"]";
				xmlData.tasks[index].@itemRewardOptional = tmpStr;
				
				tmp = 0;
				tmpStr ="[";
				
				while (tmp < 2)
				{
					tmpStr = tmpStr+"["+bmlData.readUnsignedInt()+"-"+bmlData.readUnsignedInt()+"]";
					if(tmp<1)
					{
						tmpStr = tmpStr+",";
					}
					tmp++;
				}
				tmpStr = tmpStr+"]";
				xmlData.tasks[index].@prestige = tmpStr;
				
				tmp = 0;
				tmpStr ="[";
				
				xmlData.tasks[index].@rewardBuffId = bmlData.readUnsignedInt();
				
				//tmpXml = xmlData.tasks[index].appendChild(<receiveGold/>);
				while (tmp < 2)
				{
					tmpStr = tmpStr+"["+bmlData.readUnsignedInt()+"-"+bmlData.readUnsignedInt()+"]";
					if(tmp<1)
					{
						tmpStr = tmpStr+",";
					}
					tmp++;
				}
				tmpStr = tmpStr+"]";
				xmlData.tasks[index].@receiveGold = tmpStr;
				
				
				tmp = 0;
				tmpStr ="[";
				
				while (tmp < 1)
				{
					var zw:int = bmlData.readUnsignedInt(); 
					var zw1:int = bmlData.readUnsignedInt();
					//trace("zw:"+zw+"__"+zw1);
					Global.FlagBit[index] = zw+"_"+zw1;
					tmp++;
				}
				tmp = 0;
				xmlData.tasks[index].@requiredGold = bmlData.readUnsignedInt();
				
				while (tmp < 3)
				{
					tmpStr = tmpStr+"["+bmlData.readUnsignedInt()+"-"+bmlData.readUnsignedInt()+"-"+bmlData.readUnsignedInt()+"-"+Utils.readString(bmlData)+"]";
					if(tmp<2)
					{
						tmpStr = tmpStr+",";
					}
					tmp++;
					
				}
				tmpStr = tmpStr+"]";
				xmlData.tasks[index].@questCondition = tmpStr;
				
				
				tmp = 0;
				tmpStr ="";
				
				xmlData.tasks[index].@dailyTotalCnt = bmlData.readUnsignedInt();
				
				index++;
			}

			return xmlData;
		}
		
		
		//private function addItemReward()
		/**
		 * var tmpXml:XML = xmlData.tasks[index].appendChild(<questItemReward/>);
				while(tmp<3)
				{
					tmpXml.questItemReward.@["itemID"+tmp] = bmlData.readUnsignedInt();
					tmpXml.questItemReward.@["count"+tmp] = bmlData.readUnsignedInt();
					tmp++;
				}
				tmp = 0;
				tmpStr = "";
				//tmpXml = null;
				
				tmpXml = xmlData.tasks[index].appendChild(<itemRewardOptional/>);
				while (tmp < 5)
				{
					tmpXml.itemRewardOptional.@["itemID"+tmp] = bmlData.readUnsignedInt();
					tmpXml.itemRewardOptional.@["count"+tmp] = bmlData.readUnsignedInt();
					tmp++;
				}
				tmp = 0;
				tmpStr ="";
				
				tmpXml = xmlData.tasks[index].appendChild(<prestige/>);
				while (tmp < 2)
				{
					tmpXml.prestige.@["flag"+tmp] = bmlData.readUnsignedInt();
					tmpXml.prestige.@["reward"+tmp] = bmlData.readUnsignedInt();
					tmp++;
				}
				
				tmp = 0;
				tmpStr ="";
				
				
				xmlData.tasks[index].@rewardBuffId = bmlData.readUnsignedInt();
				
				
				tmpXml = xmlData.tasks[index].appendChild(<receiveGold/>);
				while (tmp < 2)
				{
					tmpXml.receiveGold.@["flag"+tmp] = bmlData.readUnsignedInt();
					tmpXml.receiveGold.@["gold"+tmp] = bmlData.readUnsignedInt();
					tmp++;
				}
				tmp = 0;
				tmpStr ="";

				
				
				while (tmp < 1)
				{
					var zw:int = bmlData.readUnsignedInt(); 
					var zw1:int = bmlData.readUnsignedInt();
					//trace("zw:"+zw+"__"+zw1);
					Global.FlagBit[index] = zw+"_"+zw1;
					tmp++;
				}
				tmp = 0;
				tmpStr ="";
				
				xmlData.tasks[index].@requiredGold = bmlData.readUnsignedInt();
				//trace(index+" requiredGold:"+xmlData.tasks[index].@requiredGold);
				
				tmpXml = xmlData.tasks[index].appendChild(<questCondition/>);
				while (tmp < 3)
				{
					tmpXml.questCondition.@["type"+tmp] = bmlData.readUnsignedInt();
					tmpXml.questCondition.@["parm1"+tmp] = bmlData.readUnsignedInt();
					tmpXml.questCondition.@["target"+tmp] = bmlData.readUnsignedInt();
					
					//trace(index+":"+Utils.readString(bmlData));
					
					tmpXml.questCondition.@["desc"+tmp] = Utils.readString(bmlData);
					tmp++;
					
				}
				tmp = 0;
				tmpStr ="";
				
				xmlData.tasks[index].@dailyTotalCnt = bmlData.readUnsignedInt();
		 * */
		
		
	}
}